package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Journal;
import cn.wolfcode.mapper.JournalMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IJournalService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JournalServiceImpl implements IJournalService {

    @Autowired
    private JournalMapper journalMapper;


    @Override
    public void save(Journal journal) {
        journalMapper.insert(journal);
    }

    @Override
    public void delete(Long id) {
        journalMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Journal journal) {
        journalMapper.updateByPrimaryKey(journal);
    }

    @Override
    public Journal get(Long id) {
        return journalMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Journal> listAll() {
        return journalMapper.selectAll();
    }

    @Override
    public PageInfo<Journal> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Journal> journals = journalMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Journal>(journals);
    }
}
